from rest_framework import serializers
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import User
from rest_framework import response
from myproject import models as models_myproject
from datetime import datetime
from django.db.models import Q
from utils import choices

class ProjectSerializer(serializers.ModelSerializer):
    project_id=serializers.IntegerField(read_only=True)
    code=serializers.CharField(read_only=True,max_length=4000)
    file_name=serializers.CharField(read_only=True,max_length=60)
    project_detail_id=serializers.IntegerField(read_only=True)

    class Meta:
        model=models_myproject.Project
        fields=('account_id',
                'programming_language',
                'project_name',
                'file_name',
                'project_detail_id',
                'code',
                'project_id',
                )


class ProjectFileSerializer(serializers.Serializer):
    project_detail_id= serializers.IntegerField()
    file_name = serializers.CharField(max_length=60)
    code=serializers.CharField(max_length=4000)

    class Struct(object):
        def __init__(self, project_detail_id, file_name,code,):
            self.project_detail_id = project_detail_id
            self.file_name = file_name
            self.code = code

class ProjectOpenSerializer(serializers.Serializer):
    project_id=serializers.IntegerField()
    account_id=serializers.IntegerField()
    programming_language=serializers.CharField(max_length=40)
    project_name=serializers.CharField(max_length=60)
    files = ProjectFileSerializer(many=True)

    class Struct(object):
        def __init__(self, project_id, account_id,programming_language,project_name,files):
            self.project_id = project_id
            self.account_id = account_id
            self.programming_language = programming_language
            self.project_name = project_name
            self.files = files



class ProjectAllProjectSerializer(serializers.ModelSerializer):
    myproject_id=serializers.SerializerMethodField()
    class Meta:
        model=models_myproject.Project
        fields = ('programming_language',
                  'project_name',
                  'received',
                  'myproject_id')

    def get_myproject_id(self,obj):
        return obj.id

